/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('aligenie', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AppAuthHeaders {
  commonHeaders?: map[string]string,
  xAcsAligenieAccessToken?: string(name='x-acs-aligenie-access-token'),
  authorization?: string(name='Authorization'),
}

model AppAuthRequest {
  accessKey?: string(name='AccessKey'),
  appId?: string(name='AppId'),
}

model AppAuthResponseBody = {
  code?: int32(name='Code'),
  extendInfo?: map[string]any(name='ExtendInfo'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  result?: {
    accessKey?: string(name='AccessKey'),
    accessToken?: string(name='AccessToken'),
    accessTokenExpire?: long(name='AccessTokenExpire'),
    appId?: string(name='AppId'),
    refreshToken?: string(name='RefreshToken'),
    refreshTokenExpire?: long(name='RefreshTokenExpire'),
    uuid?: string(name='Uuid'),
  }(name='Result'),
}

model AppAuthResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: AppAuthResponseBody(name='body'),
}

async function appAuthWithOptions(request: AppAuthRequest, headers: AppAuthHeaders, runtime: Util.RuntimeOptions): AppAuthResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.accessKey)) {
    body['AccessKey'] = request.accessKey;
  }
  if (!Util.isUnset(request.appId)) {
    body['AppId'] = request.appId;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAligenieAccessToken)) {
    realHeaders['x-acs-aligenie-access-token'] = Util.toJSONString(headers.xAcsAligenieAccessToken);
  }
  if (!Util.isUnset(headers.authorization)) {
    realHeaders['Authorization'] = Util.toJSONString(headers.authorization);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'AppAuth',
    version = 'aiso_1.0',
    protocol = 'HTTPS',
    pathname = `/v1.0/aiso/AppAuth`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function appAuth(request: AppAuthRequest): AppAuthResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new AppAuthHeaders{};
  return appAuthWithOptions(request, headers, runtime);
}

model FaceActionRecognizeHeaders {
  commonHeaders?: map[string]string,
  xAcsAligenieAccessToken?: string(name='x-acs-aligenie-access-token'),
  authorization?: string(name='Authorization'),
}

model FaceActionRecognizeRequest {
  jsonString?: string(name='JsonString'),
  uuid?: string(name='Uuid'),
}

model FaceActionRecognizeResponseBody = {
  code?: int32(name='Code'),
  extendInfo?: map[string]any(name='ExtendInfo'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  result?: {
    actionResult?: string(name='ActionResult'),
    faceResult?: string(name='FaceResult'),
  }(name='Result'),
}

model FaceActionRecognizeResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: FaceActionRecognizeResponseBody(name='body'),
}

async function faceActionRecognizeWithOptions(request: FaceActionRecognizeRequest, headers: FaceActionRecognizeHeaders, runtime: Util.RuntimeOptions): FaceActionRecognizeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jsonString)) {
    body['JsonString'] = request.jsonString;
  }
  if (!Util.isUnset(request.uuid)) {
    body['Uuid'] = request.uuid;
  }

  var realHeaders : map[string]string = {};
  if (!Util.isUnset(headers.commonHeaders)) {
    realHeaders = headers.commonHeaders;
  }
  if (!Util.isUnset(headers.xAcsAligenieAccessToken)) {
    realHeaders['x-acs-aligenie-access-token'] = Util.toJSONString(headers.xAcsAligenieAccessToken);
  }
  if (!Util.isUnset(headers.authorization)) {
    realHeaders['Authorization'] = Util.toJSONString(headers.authorization);
  }
  var req = new OpenApi.OpenApiRequest{ 
    headers = realHeaders,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'FaceActionRecognize',
    version = 'aiso_1.0',
    protocol = 'HTTPS',
    pathname = `/v1.0/aiso/FaceActionRecognize`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function faceActionRecognize(request: FaceActionRecognizeRequest): FaceActionRecognizeResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers = new FaceActionRecognizeHeaders{};
  return faceActionRecognizeWithOptions(request, headers, runtime);
}

